package com.cyzy.controller;

import com.cyzy.entity.Curriculum;
import com.cyzy.service.ScheduleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/schedule")
public class ScheduleController {
    @Autowired
    private ScheduleService scheduleService;

    // 获取指定班级的课程
    @GetMapping("/getClassSchedule/{classId}")
    public Map<String, Object> getScheduleByClassId(@PathVariable Integer classId) {
        Map<String, Object> result = new HashMap<>();
        try {
            List<Curriculum> schedule = scheduleService.getScheduleByClassId(classId);
            result.put("success", true);
            result.put("data", schedule);
        } catch (Exception e) {
            result.put("success", false);
            result.put("message", "获取课表失败: " + e.getMessage());
        }
        return result;
    }

    // 获取指定班级和星期的课程
    @GetMapping("/getClassSchedule/{classId}/{weekday}")
    public Map<String, Object> getScheduleByClassIdAndWeekday(@PathVariable Integer classId, @PathVariable Integer weekday) {
        Map<String, Object> result = new HashMap<>();
        try {
            List<Curriculum> schedule = scheduleService.getScheduleByClassIdAndWeekday(classId, weekday);
            result.put("success", true);
            result.put("data", schedule);
        } catch (Exception e) {
            result.put("success", false);
            result.put("message", "获取课表失败: " + e.getMessage());
        }
        return result;
    }
    //传入星期几数字和上下午1/2判断是否有课
    @GetMapping("/getClassSchedule/{classId}/{weekday}/{timePeriod}")
    public Map<String, Object> getScheduleByClassIdAndWeekdayAndTimePeriod(@PathVariable Integer classId, @PathVariable Integer weekday, @PathVariable Integer timePeriod) {
        Map<String, Object> result = new HashMap<>();
        try {
            List<Curriculum> schedule = scheduleService.getScheduleByClassIdAndWeekdayAndTimePeriod(classId, weekday, timePeriod);
            result.put("success", true);
            result.put("data", schedule);
        } catch (Exception e) {
            result.put("success", false);
            result.put("message", "获取课表失败: " + e.getMessage());
        }
        return result;
    }
}
